package maosy.oauth2.password.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.ParameterBuilder
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.schema.ModelRef
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.service.Parameter
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2
import java.util.*


@Configuration
@EnableSwagger2
open class SwaggerConfig {
    @Bean
    open fun docket(): Docket? { //添加head参数配置start
        val tokenPar = ParameterBuilder()
        val pars: MutableList<Parameter> = ArrayList()
        tokenPar.name("Authorization").description("令牌").modelRef(ModelRef("string")).parameterType("header")
            .required(false).build()
        pars.add(tokenPar.build())
        return Docket(DocumentationType.SWAGGER_2)
            .enable(true)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("maosy.oauth2.password.controller"))
            .paths(PathSelectors.any())
            .build()
            .globalOperationParameters(pars) //注意这里;
    }

    private fun apiInfo(): ApiInfo? {
        return ApiInfoBuilder() // 页面标题
            .title("OAuth2权限管理API文档")
            .contact(Contact("wwz", "", "wwzwtf@qq.com"))
            .description("OAuth2维护文档")
            .version("1.0")
            .extensions(Collections.emptyList())
            .build()
    }


}